package com.woniu.controller;

import com.alibaba.fastjson.JSON;
import com.woniu.entity.Dept;
import com.woniu.entity.User;
import com.woniu.service.DeptService;
import com.woniu.vo.DeptVo;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author: 16327
 * @date: 2020/12/26 10:42
 * @description:
 */
@Controller
@RequestMapping("dept")
public class DeptController {
    @Autowired
    DeptService deptService;
    @GetMapping("Dept")
    @ResponseBody
    public String findAll1(HttpServletRequest request){
       Integer pageNum=request.getParameter("pageNum")!=null?Integer.valueOf(request.getParameter("pageNum")):1;
       Integer pageSize=request.getParameter("pageSize")!=null?Integer.valueOf(request.getParameter("pageSize")):5;
        if (pageNum!=null){

        }
        List<DeptVo> allDept = deptService.findAllDept(pageNum,pageSize);
        String s = JSON.toJSONString(allDept);
        return s;
    }
    @DeleteMapping("Dept/{deptid}")
    @ResponseBody
    public String delDept(@PathVariable("deptid") Integer deptid){
        int i = deptService.delDept(deptid);
        String s = JSON.toJSONString(i);
        return s;
    }
    @GetMapping("Dept/{deptid}")
    @ResponseBody
    public String findDept(@PathVariable("deptid") Integer deptid){
        DeptVo deptVo = deptService.selectByDeptid(deptid);
        String s = JSON.toJSONString(deptVo);
        return s;
    }
    @PutMapping("Dept")
    @ResponseBody
    public String updateDept(@RequestBody Dept dept){
        int i = deptService.updateDept(dept);
        String s = JSON.toJSONString(i);
        return s;
    }
    @PostMapping("Dept")
    @ResponseBody
    public String insertDept(@RequestBody Dept dept){
        int i = deptService.insertDept(dept);
        String s = JSON.toJSONString(i);
        return s;
    }
    @GetMapping("findDeptByLike")
    @ResponseBody
    public List<DeptVo> findDeptByLike(@RequestBody Dept dept){
        List<DeptVo> allDept=deptService.selectDeptByLike(dept);
        return allDept;
    }

    @RequestMapping("user")
    @ResponseBody
    public void user1(@RequestBody User user){
        System.out.println(user);
    }

    @RequestMapping("user1")
    @ResponseBody
    public void user2(@RequestBody User user){
        System.out.println(user);
    }



}
